package com.itheima.udpqun;

import java.io.IOException;
import java.net.DatagramPacket;
import java.net.InetAddress;
import java.net.MulticastSocket;

public class RecevieClient2 {

    public static void main(String[] args) throws IOException {
        //创建对象
        MulticastSocket ms = new MulticastSocket(8888);
        //加入群聊
        InetAddress qunming = InetAddress.getByName("224.0.1.0");
        ms.joinGroup(qunming);
        //找容器
        while (true) {
            byte[] bytes = new byte[1024 * 64];
            DatagramPacket dp = new DatagramPacket(bytes, bytes.length);


            //接受数据
            ms.receive(dp);

            // 查看数据
            int length = dp.getLength();
            System.out.println(new String(bytes, 0, length));
        }


        //释放资源
       // ms.close();


    }
}
